forked from electricdusk/rushlink
		
	Add marshalling functions for gob
This removes a lot of the boilerplate code that comes with (un)marshalling to gob encoding in Go.
This commit is contained in:
		
							parent
							
								
									983fa8d389
								
							
						
					
					
						commit
						a6edcd222e
					
				
							
								
								
									
										20
									
								
								gobmarsh/marshal.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								gobmarsh/marshal.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | |||||||
|  | package gobmarsh | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"bytes" | ||||||
|  | 	"encoding/gob" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func Marshal(v interface{}) ([]byte, error) { | ||||||
|  | 	b := new(bytes.Buffer) | ||||||
|  | 	err := gob.NewEncoder(b).Encode(v) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, err | ||||||
|  | 	} | ||||||
|  | 	return b.Bytes(), nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func Unmarshal(data []byte, v interface{}) error { | ||||||
|  | 	b := bytes.NewBuffer(data) | ||||||
|  | 	return gob.NewDecoder(b).Decode(v) | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user