@@ -658,105 +658,6 @@ void AsciiWrite(const FunctionCallbackInfo<Value>& args) {
658658}
659659
660660
661- static inline void Swizzle (char * start, unsigned int len) {
662- char * end = start + len - 1 ;
663- while (start < end) {
664- char tmp = *start;
665- *start++ = *end;
666- *end-- = tmp;
667- }
668- }
669-
670-
671- template <typename T, enum Endianness endianness>
672- void ReadFloatGeneric (const FunctionCallbackInfo<Value>& args) {
673- THROW_AND_RETURN_UNLESS_BUFFER (Environment::GetCurrent (args), args[0 ]);
674- SPREAD_ARG (args[0 ], ts_obj);
675-
676- uint32_t offset = args[1 ]->Uint32Value ();
677- CHECK_LE (offset + sizeof (T), ts_obj_length);
678-
679- union NoAlias {
680- T val;
681- char bytes[sizeof (T)];
682- };
683-
684- union NoAlias na;
685- const char * ptr = static_cast <const char *>(ts_obj_data) + offset;
686- memcpy (na.bytes , ptr, sizeof (na.bytes ));
687- if (endianness != GetEndianness ())
688- Swizzle (na.bytes , sizeof (na.bytes ));
689-
690- args.GetReturnValue ().Set (na.val );
691- }
692-
693-
694- void ReadFloatLE (const FunctionCallbackInfo<Value>& args) {
695- ReadFloatGeneric<float , kLittleEndian >(args);
696- }
697-
698-
699- void ReadFloatBE (const FunctionCallbackInfo<Value>& args) {
700- ReadFloatGeneric<float , kBigEndian >(args);
701- }
702-
703-
704- void ReadDoubleLE (const FunctionCallbackInfo<Value>& args) {
705- ReadFloatGeneric<double , kLittleEndian >(args);
706- }
707-
708-
709- void ReadDoubleBE (const FunctionCallbackInfo<Value>& args) {
710- ReadFloatGeneric<double , kBigEndian >(args);
711- }
712-
713-
714- template <typename T, enum Endianness endianness>
715- uint32_t WriteFloatGeneric (const FunctionCallbackInfo<Value>& args) {
716- SPREAD_ARG (args[0 ], ts_obj);
717-
718- T val = args[1 ]->NumberValue ();
719- uint32_t offset = args[2 ]->Uint32Value ();
720- CHECK_LE (offset + sizeof (T), ts_obj_length);
721-
722- union NoAlias {
723- T val;
724- char bytes[sizeof (T)];
725- };
726-
727- union NoAlias na = { val };
728- char * ptr = static_cast <char *>(ts_obj_data) + offset;
729- if (endianness != GetEndianness ())
730- Swizzle (na.bytes , sizeof (na.bytes ));
731- memcpy (ptr, na.bytes , sizeof (na.bytes ));
732- return offset + sizeof (na.bytes );
733- }
734-
735-
736- void WriteFloatLE (const FunctionCallbackInfo<Value>& args) {
737- THROW_AND_RETURN_UNLESS_BUFFER (Environment::GetCurrent (args), args[0 ]);
738- args.GetReturnValue ().Set (WriteFloatGeneric<float , kLittleEndian >(args));
739- }
740-
741-
742- void WriteFloatBE (const FunctionCallbackInfo<Value>& args) {
743- THROW_AND_RETURN_UNLESS_BUFFER (Environment::GetCurrent (args), args[0 ]);
744- args.GetReturnValue ().Set (WriteFloatGeneric<float , kBigEndian >(args));
745- }
746-
747-
748- void WriteDoubleLE (const FunctionCallbackInfo<Value>& args) {
749- THROW_AND_RETURN_UNLESS_BUFFER (Environment::GetCurrent (args), args[0 ]);
750- args.GetReturnValue ().Set (WriteFloatGeneric<double , kLittleEndian >(args));
751- }
752-
753-
754- void WriteDoubleBE (const FunctionCallbackInfo<Value>& args) {
755- THROW_AND_RETURN_UNLESS_BUFFER (Environment::GetCurrent (args), args[0 ]);
756- args.GetReturnValue ().Set (WriteFloatGeneric<double , kBigEndian >(args));
757- }
758-
759-
760661void ByteLengthUtf8 (const FunctionCallbackInfo<Value> &args) {
761662 CHECK (args[0 ]->IsString ());
762663
@@ -962,16 +863,6 @@ void Initialize(Local<Object> target,
962863 env->SetMethod (target, " indexOfNumber" , IndexOfNumber);
963864 env->SetMethod (target, " indexOfString" , IndexOfString);
964865
965- env->SetMethod (target, " readDoubleBE" , ReadDoubleBE);
966- env->SetMethod (target, " readDoubleLE" , ReadDoubleLE);
967- env->SetMethod (target, " readFloatBE" , ReadFloatBE);
968- env->SetMethod (target, " readFloatLE" , ReadFloatLE);
969-
970- env->SetMethod (target, " writeDoubleBE" , WriteDoubleBE);
971- env->SetMethod (target, " writeDoubleLE" , WriteDoubleLE);
972- env->SetMethod (target, " writeFloatBE" , WriteFloatBE);
973- env->SetMethod (target, " writeFloatLE" , WriteFloatLE);
974-
975866 target->Set (env->context (),
976867 FIXED_ONE_BYTE_STRING (env->isolate (), " kMaxLength" ),
977868 Integer::NewFromUnsigned (env->isolate (), kMaxLength )).FromJust ();
0 commit comments