Inital Commit
[oweals/finalsclub.git] / node_modules / mongodb / external-libs / bson / binary.h
1 #ifndef BINARY_H_
2 #define BINARY_H_
3
4 #include <node.h>
5 #include <node_object_wrap.h>
6 #include <v8.h>
7
8 using namespace v8;
9 using namespace node;
10
11 class Binary : public ObjectWrap {  
12   public:
13     char *data;
14     uint32_t number_of_bytes;
15     uint32_t sub_type;
16     uint32_t index;
17     
18     Binary(uint32_t sub_type, uint32_t number_of_bytes, uint32_t index, char *data);
19     ~Binary();    
20
21     // Has instance check
22     static inline bool HasInstance(Handle<Value> val) {
23       if (!val->IsObject()) return false;
24       Local<Object> obj = val->ToObject();
25       return constructor_template->HasInstance(obj);
26     }    
27
28     // Functions available from V8
29     static void Initialize(Handle<Object> target);    
30     static Handle<Value> ToString(const Arguments &args);
31     static Handle<Value> Inspect(const Arguments &args);
32     static Handle<Value> Data(const Arguments &args);
33     static Handle<Value> Length(const Arguments &args);
34     static Handle<Value> Put(const Arguments &args);
35     static Handle<Value> Write(const Arguments &args);
36     static Handle<Value> Read(const Arguments &args);
37     
38     /**
39      * Writes this binary data into node Buffer passed as first js arg. 
40      * Optional second js arg: internal data offset of this binary (Integer)
41      * Up to Min(Buffer.length, Binary.length - offset) bytes will be writen into buffer.
42      * Return number of bytes actually written into buffer.
43      */
44     static Handle<Value> ReadInto(const Arguments &args);
45
46     // Constructor used for creating new Long objects from C++
47     static Persistent<FunctionTemplate> constructor_template;
48
49     // Getter and Setter for object values
50     static Handle<Value> SubtypeGetter(Local<String> property, const AccessorInfo& info);
51     static void SubtypeSetter(Local<String> property, Local<Value> value, const AccessorInfo& info);
52     
53   private:
54     static Handle<Value> New(const Arguments &args);
55 };
56
57 #endif  // BINARY_H_